package com.tjec.project.projectWorkbench.controller;

import java.util.List;

import com.tjec.common.utils.DateUtils;
import com.tjec.project.projectWorkbench.domain.BmsProject;
import com.tjec.project.projectWorkbench.service.IBmsProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjec.framework.aspectj.lang.annotation.Log;
import com.tjec.framework.aspectj.lang.enums.BusinessType;
import com.tjec.project.projectWorkbench.domain.BmsProjectContract;
import com.tjec.project.projectWorkbench.service.IBmsProjectContractService;
import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.common.utils.poi.ExcelUtil;
import com.tjec.framework.web.page.TableDataInfo;

/**
 * 项目合同Controller
 * 
 * @author tjec
 * @date 2020-04-26
 */
@Api(value = "项目主页-项目合同" , tags = {"项目主页-项目合同接口"})
@RestController
@RequestMapping("/project/contract")
public class BmsProjectContractController extends BaseController
{
    @Autowired
    private IBmsProjectContractService bmsProjectContractService;

    @Autowired
    private IBmsProjectService bmsProjectService;

    /**
     * 查询项目合同列表
     */
    @ApiOperation("查询项目合同列表")
    @GetMapping("/list")
//    @PreAuthorize("@ss.hasPermi('project:contract:list')")
    public TableDataInfo list(BmsProjectContract bmsProjectContract)
    {
        BmsProject bmsProject = bmsProjectService.selectBmsProjectByGuid(bmsProjectContract.getProjectId());
        if(bmsProject==null){
            AjaxResult.error();
        }
        bmsProjectContract.setProjectId(bmsProject.getCode());
        startPage();
        List<BmsProjectContract> list = bmsProjectContractService.selectBmsProjectContractList(bmsProjectContract);
        return getDataTable(list);
    }

    /**
     * 获取项目合同详细信息
     */
    @ApiOperation("获取项目合同详细信息")
    @ApiImplicitParam(name = "guid", value = "项目合同guid", required = true, dataType = "String", paramType = "path")
//    @PreAuthorize("@ss.hasPermi('project:contract:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(bmsProjectContractService.selectBmsProjectContractByGuid(guid));
    }

    /**
     * 新增项目合同（项目合同同步）【需同步经营管理系统项目合同】
     */
    @ApiOperation("项目合同同步")
    @ApiImplicitParam(name = "bmsProjectContract", value = "项目合同同步", dataType = "BmsProjectContract")
//    @PreAuthorize("@ss.hasPermi('project:contract:synchronize')")
    @Log(title = "项目合同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult synchronize(@RequestBody BmsProjectContract bmsProjectContract)
    {
        BmsProject bmsProject = bmsProjectService.selectBmsProjectByGuid(bmsProjectContract.getProjectId());
        if(bmsProject==null){
            AjaxResult.error();
        }
        return toAjax(bmsProjectContractService.synchronous(bmsProject.getCode(),bmsProjectContractService.selectMaxTime()));
    }

    /**
     * 修改项目合同
     */
    @ApiOperation("修改项目合同")
    @ApiImplicitParam(name = "bmsProjectContract", value = "修改项目合同", dataType = "BmsProjectContract")
//    @PreAuthorize("@ss.hasPermi('project:contract:edit')")
    @Log(title = "项目合同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsProjectContract bmsProjectContract)
    {
        return toAjax(bmsProjectContractService.updateBmsProjectContract(bmsProjectContract));
    }
}
